﻿using FitnessTracker.Packet;

namespace FitnessTrackerCoreUnitTests
{
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    [TestClass]
    public class PacketIntegrityValidationTests
    {

        #region Packet With Valid CRC

        readonly byte[] packetWithValidCRC = new byte[]
                            {
                                0x02,  //STX
                                0x26,  //MessageID
                                0x37,  //DLC
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x85, //CRC Valid
                                0x03  //ETX
                            };
        #endregion

        #region Packet With Invalid CRC

        readonly byte[] packetWithInvalidCRC = new byte[]
                            {
                                0x02,  //STX
                                0x26,  //MessageID
                                0x37,  //DLC
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20,
                                0x20, //CRC Inalid
                                0x03  //ETX
                            };
        #endregion

        [TestMethod]
        public void CRCValidationTest()
        {
            Assert.IsTrue(HxMPacketIntegrityValidator.IsCRCValid(packetWithValidCRC));
            Assert.IsFalse(HxMPacketIntegrityValidator.IsCRCValid(packetWithInvalidCRC));
        }
    }
}
